﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows.Data;
using System.Windows;
using System.Globalization;
using System.Windows.Media;

namespace CommunicationDesktopApplication
{
    [ValueConversion(typeof(Byte[]), typeof(SolidColorBrush))]
    public class BytesToBackground : IValueConverter
    {
        public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
        {
            Byte[] colorArr = (Byte[])value;
            return new SolidColorBrush(Color.FromRgb(colorArr[0], colorArr[1], colorArr[2]));
        }
        public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
        {
            SolidColorBrush brushValue = value as SolidColorBrush;
            if (brushValue != null)
                return new Byte[] { brushValue.Color.A, brushValue.Color.R, brushValue.Color.G, brushValue.Color.B};
            else
                return DependencyProperty.UnsetValue;
        }
    }
}
